<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    用户名:<input type="text" id="name"><br>
    密 码: <input type="password" id="pwd"><br>
    <button id="btn">登录</button>
    <script>
        // 判断，如果在本地存储中能找到name和password，那就代表着有记录，就渲染到页面上去
        if(localStorage.getItem('name')){
            document.getElementById('name').value = localStorage.getItem('name')
        }
        if(localStorage.getItem('password')){
            document.getElementById('pwd').value = localStorage.getItem('password')
        }

        // 用户点击登录则自动记住用户名和密码
        document.getElementById('btn').onclick = ()=>{
            localStorage.setItem('name',document.getElementById('name').value)
            localStorage.setItem('password',document.getElementById('pwd').value)
        }
    </script>
</body>
</html>